#include <stdio.h>
#include <dlfcn.h>

int main(int argc, char* argv[])
{
	printf("enter @ func:%s , line:%3d , file:%s .\n",__FUNCTION__, __LINE__, __FILE__);

	float* pf;
	
	void *dp=NULL;
	float* (*pgetfloatpoint)(void);
	char * error=NULL;

	printf("d-call libfoo2.so start @ func:%s , line:%3d , file:%s .\n",__FUNCTION__, __LINE__, __FILE__);
	if(!(dp=dlopen("./libfoo2.so", RTLD_LAZY)))
	{
		printf("load libfoo2.so falied at main %d.\n", __LINE__);
		return 1;
	}

	pgetfloatpoint=(float* (*) (void) )dlsym(dp, "getfloatpoint");
	error=dlerror();

	if(error)
	{
		printf("dlerror exit at main %d.\n", __LINE__);
		return 1;
	}
	
	pf=pgetfloatpoint();

	/* dlclose(dp);*/ /* have the output "result.aix.v1.log" */
	printf("d-call libfoo2.so finish @ func:%s , line:%3d , file:%s .\n",__FUNCTION__, __LINE__, __FILE__);

	void *dp2=NULL;
	void (*pcallfoo2)(float*, float);
	char * error2=NULL;

	printf("d-call libfoo1.so start @ func:%s , line:%3d , file:%s .\n",__FUNCTION__, __LINE__, __FILE__);
	if(!(dp2=dlopen("./libfoo1.so", RTLD_LAZY)))
	{
		printf("load libfoo1.so falied at main %d.\n", __LINE__);
		return 1;
	}

	pcallfoo2=(void (*) (float*, float) ) dlsym(dp2, "callfoo2");
	error2=dlerror();

	if(error2)
	{
		printf("dlerror exit at main %d.\n", __LINE__);
		return 1;
	}
	
	pcallfoo2(pf, 3.0f);

	dlclose(dp2);
	dlclose(dp); /* have the output "result.aix.v2.log" */
	printf("d-call libfoo1.so finish @ func:%s , line:%3d , file:%s .\n",__FUNCTION__, __LINE__, __FILE__);

	printf("exit @ func:%s , line:%3d , file:%s .\n",__FUNCTION__, __LINE__, __FILE__);
	return 0;
};

